package org.an.proj.contacts.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * 创建时间：2017年02月06日17:28 <br>
 * 作者：fuchaoyang <br>
 * 描述：用于Intent跳转
 */

public class IntentUtil {
  private static final String TAG = "IntentUtil";

  public static void goToOthers(Context context, Class<?> cls) {
    goToOthers(context, cls, new Bundle());
  }

  public static void goToOthersF(Activity context, Class<?> cls) {
    goToOthers(context, cls);
    context.finish();
  }

  public static void goToOthers(Context context, Class<?> cls, Bundle bundle) {
    Intent intent = new Intent(context, cls);
    intent.putExtras(bundle);
    context.startActivity(intent);
  }

  public static void goToOthersF(Activity context, Class<?> cls, Bundle bundle) {
    goToOthers(context, cls, bundle);
    context.finish();
  }

  public static void goToOthersForResult(Activity context, Class<?> cls, Bundle bundle,
      int requestCode) {
    Intent intent = new Intent(context, cls);
    intent.putExtras(bundle);
    context.startActivityForResult(intent, requestCode);
  }

  public static void backForResult(Activity context, Bundle bundle, int resultCode) {
    Intent intent = new Intent();
    intent.putExtras(bundle);
    context.setResult(resultCode, intent);
    context.finish();
  }

  public static void upToHome(Activity context, Class<?> cls) {
    upToHome(context, cls, null);
  }

  public static void upToHome(Activity context, Class<?> cls, Bundle bundle) {
    Intent intent = new Intent(context, cls);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtras(bundle);
    context.startActivity(intent);
    context.finish();
  }

  public static void homeAction(Activity context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addCategory(Intent.CATEGORY_HOME);
    context.startActivity(intent);
  }
}
